package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.CommentBean;
import com.project.bean.ProductBean;
import com.project.mapper.ICommentMapper;
import com.project.mapper.IProductMapper;
import com.project.service.ICommentService;
import com.project.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class ProductServiceImpl implements IProductService {
    @Autowired
    private IProductMapper mapper;
    @Autowired
    ICommentMapper commentMapper;
    @Override
    public ProductBean findById(Integer id) {
        ProductBean product = mapper.selectById(id);
        QueryWrapper<CommentBean> qw = new QueryWrapper<>();
        qw.eq("fk_productId",id);
        product.setComNum(commentMapper.selectCount(qw).intValue());

        product.setComList(mapper.findByProduct(id));



        return product;
    }

    @Override
    public IPage<ProductBean> cutByItem(Integer pageNO, String name) {

        return mapper.cutByItem(new Page(pageNO,3),name);
    }
}
